package com.itheima.tlias.controller;

import com.itheima.tlias.comment.MyComment;
import com.itheima.tlias.dto.AddStudentDto;
import com.itheima.tlias.dto.CheckStudentDto;
import com.itheima.tlias.dto.UpdateStudentDto;
import com.itheima.tlias.service.StudentService;
import com.itheima.tlias.vo.PageBean;
import com.itheima.tlias.vo.Result;
import com.itheima.tlias.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //大字段 @MyComment(desc = "学生条件 分页查询")
    @GetMapping
    public Result<PageBean<StudentVo>> students(CheckStudentDto dto) {
        PageBean<StudentVo> students = studentService.studentPage(dto);
        return Result.success(students);
    }
    @MyComment(desc = "学生批量删除")
    @DeleteMapping("/{ids}")
    public Result<Void> deleteStudent(@PathVariable List<Integer> ids) {
        studentService.deleteStudents(ids);
        return Result.success();
    }
    //大字段@MyComment(desc = "学生新增")
    @PostMapping
    public Result<Void> addStudent(@RequestBody AddStudentDto dto) {
        studentService.addStudent(dto);
        return Result.success();
    }
    @MyComment(desc = "学生修改 回显功能")
    @GetMapping("{id}")
    public Result<StudentVo> getById(@PathVariable("id") Integer id) {
        StudentVo vo = studentService.getById(id);
        return Result.success(vo);
    }
    @MyComment(desc = "学生修改基本信息")
    @PutMapping
    public Result<Void> updateStudent(@RequestBody UpdateStudentDto dto) {
        studentService.updateStudent(dto);
        return Result.success();
    }
    @MyComment(desc = "学生违纪")
    @PutMapping("/violation/{id}/{score}")
    public Result<Void> violateDiscipline(@PathVariable Integer id, @PathVariable Integer score){
        studentService.violateDiscipline(id,score);
        return Result.success();
    }

}
